package com.ruoyi.carService.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.api.domain.Merchant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.api.domain.Merchant;
import com.ruoyi.carService.service.IMerchantService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 商户管理Controller
 * 
 * @author ruoyi
 * @date 2024-09-07
 */
@RestController
@RequestMapping("/merchant")
public class MerchantController extends BaseController
{
    @Autowired
    private IMerchantService merchantService;

    @RequestMapping("/countshj")
    public Map selectNewMerchantCount(){
        Map map = new HashMap();
        map.put("countshj", merchantService.selectNewMerchantCount());
        return map;
    }
    @RequestMapping("/countnumber")
    public Map selectMerchantCountNumber(){
        Map map = new HashMap();
        map.put("countnumber", merchantService.selectMerchantCountNumber());
        return map;
    }

    /**
     * 查询商户列表
    /**
     * 查询商户管理列表
     */
//    @RequiresPermissions("carService:merchant:list")
    @RequestMapping("/list")
    public TableDataInfo list(Merchant merchant)
    {
        startPage();
        List<Merchant> list = merchantService.selectMerchantList(merchant);
        return getDataTable(list);
    }

    @RequiresPermissions("carService:merchant:list")
    @GetMapping("/rank")
    public TableDataInfo rank(Merchant merchant)
    {
        startPage();
        List<Merchant> list = merchantService.selectMerchantListRank(merchant);
        return getDataTable(list);
    }

    /**
     * 导出商户管理列表
     */
    @RequiresPermissions("carService:merchant:export")
    @Log(title = "商户管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Merchant merchant)
    {
        List<Merchant> list = merchantService.selectMerchantList(merchant);
        ExcelUtil<Merchant> util = new ExcelUtil<Merchant>(Merchant.class);
        util.exportExcel(response, list, "商户管理数据");
    }

    /**
     * 获取商户管理详细信息
     */
//    @RequiresPermissions("carService:merchant:query")
    @RequestMapping(value = "/{merchantId}")
    public AjaxResult getInfo(@PathVariable("merchantId") Long merchantId)
    {
        return success(merchantService.selectMerchantByMerchantId(merchantId));
    }

    /**
     * 新增商户管理
     */
//    @RequiresPermissions("carService:merchant:add")
    @Log(title = "商户管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Merchant merchant)
    {
        return toAjax(merchantService.insertMerchant(merchant));
    }

    /**
     * 修改商户管理
     */
    @RequiresPermissions("carService:merchant:edit")
    @Log(title = "商户管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Merchant merchant)
    {
        return toAjax(merchantService.updateMerchant(merchant));
    }

    @RequiresPermissions("carService:merchant:edit")
    @RequestMapping("/updateStatus")
    public AjaxResult updateStatus(@RequestBody String status)
    {
        return toAjax(merchantService.updateMerchantStatus(status));
    }

    /**
     * 删除商户管理
     */
    @RequiresPermissions("carService:merchant:remove")
    @Log(title = "商户管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{merchantIds}")
    public AjaxResult remove(@PathVariable Long[] merchantIds)
    {
        return toAjax(merchantService.deleteMerchantByMerchantIds(merchantIds));
    }
}
